oo::class create ActionTasks {
    variable beforeInsert afterInsert beforeDelete \
        afterDelete beforeReplace afterReplace \
        beforeMarkSetInsert afterMarkSetInsert \
        beforeSee afterSee

    constructor {} {
        my purgeTasks
    }

    method purgeTasks {} {
        set beforeInsert {}
        set afterInsert {}
        set beforeDelete {}
        set afterDelete {}
        set beforeReplace {}
        set afterReplace {}
        set beforeMarkSetInsert {}
        set afterMarkSetInsert {}
        set beforeSee {}
        set afterSee {}
    }

    method setTasks {type tasks} {
        eval [list set \$$type $tasks]
    }

    method getTasks {type} {
        return [eval [list set $type]]
    }

    method appendTask {type task} {
        eval [list lappend $type $task]
    }

    method popTask {type} {
        set tasks [my getTasks $type]
        set ret [lindex $tasks 0]
        my setTask [lreplace $tasks 0 0]
        return $ret
    }

    method runTasks {type args} {
        foreach t [my getTasks $type] {
            if ![string first before $type] {
                eval $t $args
            } else {
                runAfterIdle [concat $t $args]
            }
        }
    }

    unexport getTasks setTask
}